/* GUI CONVERTED from rcdel.p (converter v1.76) Fri May  3 13:21:09 2002 */
/* rcdel.p - Release Management Customer Schedules                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.12.1.11 $                                                        */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 7.0    LAST MODIFIED: 01/29/92           BY: WUG *F110*          */
/* REVISION: 7.0    LAST MODIFIED: 03/20/92           BY: WUG *F312*          */
/* REVISION: 7.3    LAST MODIFIED: 10/13/92           BY: WUG *G462*          */
/* REVISION: 7.3    LAST MODIFIED: 08/13/93           BY: WUG *GE19*          */
/* REVISION: 7.4    LAST MODIFIED: 09/29/93           BY: WUG *H142*          */
/* REVISION: 7.3    LAST MODIFIED: 04/14/94           BY: WUG *GJ34*          */
/*                                 08/27/94           BY: BCM *GL61*          */
/*                                 03/03/95           BY: aed *G0JC*          */
/* REVISION: 7.4    LAST MODIFIED: 08/29/95           BY: bcm *G0TB*          */
/* REVISION: 7.4    LAST MODIFIED: 07/23/96           BY: *G29C* Ajit Deodhar */
/* REVISION: 8.6    LAST MODIFIED: 05/01/97   BY: *K0CV* Vinay Nayak-Sujir    */
/* REVISION: 8.6    LAST MODIFIED: 05/21/97   BY: *K0DC* Taek-Soo Chang       */
/* REVISION: 8.6    LAST MODIFIED: 06/11/97   BY: *J1SX* Aruna Patil          */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane            */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 8.6e   LAST MODIFIED: 08/13/98   BY: *J2SN* Dana Tunstall        */
/* REVISION: 9.1    LAST MODIFIED: 09/17/99   BY: *N031* Kedar Deherkar       */
/* REVISION: 9.1    LAST MODIFIED: 10/12/99   BY: *N004* Steve Nugent         */
/* REVISION: 9.1    LAST MODIFIED: 12/08/99   BY: *N003* Patrick Rowan        */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1    LAST MODIFIED: 05/10/00   BY: *N08Y* Mark Christian       */
/* REVISION: 9.1    LAST MODIFIED: 08/10/00   BY: *M0QW* Falguni Dalal        */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* REVISION: 9.1    LAST MODIFIED: 09/05/00   BY: *N0R9* Mudit Mehta          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.12.1.9     BY: Jean Miller    DATE: 03/22/01 ECO: *P008*       */
/* $Revision: 1.12.1.11 $    BY: Katie Hilbert  DATE: 04/15/02 ECO: *P03J*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* SCHEDULE ARCHIVE/DELETE */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

{rcrpvar.i}
define variable date_from     as date label "Created".
define variable date_to       as date label {t001.i}.
define variable sortoption    as integer label "Sort Option" format "9"
                              initial 1.
define variable sortextoption as character extent 2 format "x(66)".
define variable schtype       like sch_type initial 1.
define variable rdelete       like mfc_logical label "Delete".
define variable archive       like mfc_logical label "Archive" initial no.
define variable filename      as character format "x(12)" label "Archive File".
define variable detail_only   like mfc_logical label "Detail Only".
define variable so_db         as   character.
define variable  incl_plan    like mfc_logical initial yes
                              label "Plan" no-undo.
define variable  incl_ship    like mfc_logical initial no
                              label "Ship" no-undo.
define variable  incl_reqd    like mfc_logical initial no
                              label "Required Ship" no-undo.
define variable  incl_seq     like mfc_logical initial no
                              label "Sequence" no-undo.
define variable inactive_only like mfc_logical initial yes
                              label "Inactive Schedule Only" no-undo.

define variable  inclsch_label as character format "x(25)" no-undo.
define variable  process_schd  as logical extent 3 initial no no-undo.
define variable  ctr           as integer initial 0 no-undo.
define variable  schd-error    as logical initial false no-undo.
define variable  header-needed as logical initial false no-undo.

define variable  using_seq_schedules like mfc_logical initial no no-undo.
define variable  l_msgdesc           like msg_desc extent 3 no-undo.

define  new shared stream   history.

sortextoption[1] = "1 - " +
                   getTermLabel("BY_SHIP-FROM",12)      + "," +
                   getTermLabel("CUSTOMER",4)           + "," +
                   getTermLabel("SHIP-TO",7)            + "," +
                   getTermLabel("ORDER",5)              + "," +
                   getTermLabel("DOCK",4)               + "," +
                   getTermLabel("ITEM",4)               + "," +
                   getTermLabel("PURCHASE_ORDER",2)     + "," +
                   getTermLabel("CUSTOMER_REFERENCE",8) + "," +
                   getTermLabel("MODEL_YEAR",8).

sortextoption[2] = "2 - " +
                   getTermLabel("BY_ITEM",7)            + "," +
                   getTermLabel("SHIP-FROM",9)          + "," +
                   getTermLabel("CUSTOMER",4)           + "," +
                   getTermLabel("SHIP-TO",7)            + "," +
                   getTermLabel("ORDER",5)              + "," +
                   getTermLabel("DOCK",4)               + "," +
                   getTermLabel("PURCHASE_ORDER",2)     + "," +
                   getTermLabel("CUSTOMER_REFERENCE",8) + "," +
                   getTermLabel("MODEL_YEAR",8).

inclsch_label =    getTermLabel("INCLUDE_SCHEDULE_TYPE",25).


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shipfrom_from        colon 15 label "Ship-From"
   shipfrom_to          colon 45 label {t001.i}
   cust_from            colon 15
   cust_to              colon 45 label {t001.i}
   shipto_from          colon 15
   shipto_to            colon 45 label {t001.i}
   dock_from            colon 15
   dock_to              colon 45 label {t001.i}
   part_from            colon 15
   part_to              colon 45 label {t001.i}
   po_from              colon 15 format "x(22)"
   po_to                colon 45 label {t001.i} format "x(22)"
   custref_from         colon 15 format "x(22)"
   custref_to           colon 45 label {t001.i} format "x(22)"
   modelyr_from         colon 15
   modelyr_to           colon 45 label {t001.i}
   order_from           colon 15
   order_to             colon 45 label {t001.i}
   date_from            colon 15
   date_to              colon 45 label {t001.i}
   sortoption           colon 15
   sortextoption[1]     at 7 no-label
   sortextoption[2]     at 7 no-label
   inclsch_label        at 7 no-label
   inactive_only        colon 63
   incl_plan            colon 20
   detail_only          colon 63
   incl_ship            colon 20
   rdelete              colon 63
   incl_reqd            colon 20
   archive              colon 45
   filename             colon 63
   incl_seq             colon 20
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* VARIABLE DEFINITIONS FOR gpfile.i */
{gpfilev.i}

/* DETERMINE IF SEQUENCE SCHEDULES IS INSTALLED */
{gpfile.i &file_name = """"rcf_ctrl""""}

if can-find (mfc_ctrl where
             mfc_field = "enable_sequence_schedules"  and
             mfc_logical)
   and file_found
then
   using_seq_schedules = yes.


/*GUI*/ {mfguirpa.i false "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:


   output stream history close.

   display
      sortextoption
      inclsch_label
   with frame a.

   if shipfrom_to = hi_char then shipfrom_to = "".
   if cust_to     = hi_char then cust_to     = "".
   if shipto_to   = hi_char then shipto_to   = "".
   if dock_to     = hi_char then dock_to     = "".
   if part_to     = hi_char then part_to     = "".
   if po_to       = hi_char then po_to       = "".
   if custref_to  = hi_char then custref_to  = "".
   if modelyr_to  = hi_char then modelyr_to  = "".
   if order_to    = hi_char then order_to    = "".

   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   if inactive_only = no then do:
      /* ACTIVE SCHEDULES WOULD ALSO BE DELETED */
      {pxmsg.i &MSGNUM=8106 &ERRORLEVEL=2}
   end.

   if rdelete then do:

      if archive then do:

         filename = "cs"
            + substring(string(year(today),"9999"),3,2)
            + string(month(today),"99")
            + string(day(today),"99")
            + ".hst".

         display
            filename
         with frame a.

         /* Archive files should be backed up and deleted from disk */
         {pxmsg.i &MSGNUM=51 &ERRORLEVEL=1}

         if search(filename) <> ? then do:
            /* <filename> exists, archive data will be appended */
            {pxmsg.i &MSGNUM=52 &ERRORLEVEL=2 &MSGARG1=filename}
         end.
         output stream history to value(filename) append.

      end.
      else
         display
            "" @ filename
         with frame a.

   end. /* if rdelete */

   else do:

      display
         "" @ filename
      with frame a.

      if archive then do:
         /* Cannot archive unless delete is yes */
         {pxmsg.i &MSGNUM=7739 &ERRORLEVEL=3}
         /*GUI UNDO removed */ RETURN ERROR.
      end.
   end.

   if shipfrom_to = "" then shipfrom_to = hi_char.
   if cust_to     = "" then cust_to     = hi_char.
   if shipto_to   = "" then shipto_to   = hi_char.
   if dock_to     = "" then dock_to     = hi_char.
   if part_to     = "" then part_to     = hi_char.
   if po_to       = "" then po_to       = hi_char.
   if custref_to  = "" then custref_to  = hi_char.
   if modelyr_to  = "" then modelyr_to  = hi_char.
   if order_to    = "" then order_to    = hi_char.

   assign
      process_schd[1] = if incl_plan then yes else no
      process_schd[2] = if incl_ship then yes else no
      process_schd[3] = if incl_reqd then yes else no.

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:




   {mfphead.i}

   if sortoption = 1 then do:

      for each scx_ref no-lock
         where scx_type = 1
           and scx_shipfrom >= shipfrom_from and scx_shipfrom <= shipfrom_to
           and scx_shipto >= shipto_from and scx_shipto <= shipto_to
           and scx_part >= part_from and scx_part <= part_to
           and scx_po >= po_from and scx_po <= po_to
           and scx_custref >= custref_from and scx_custref <= custref_to
           and scx_modelyr >= modelyr_from and scx_modelyr <= modelyr_to
           and scx_order  >= order_from  and scx_order <= order_to,
         each sod_det no-lock
        where sod_nbr = scx_order and sod_line = scx_line
          and sod_dock >= dock_from and sod_dock <= dock_to,
         each so_mstr no-lock
        where so_nbr = sod_nbr
          and so_cust >= cust_from and so_cust <= cust_to
       break by scx_shipfrom by so_cust by scx_shipto by scx_order
             by sod_dock by sod_part by sod_contr_id
             by scx_custref by scx_modelyr:

         /* Only Select Orders created in the current database */
         assign
            so_db = trim(substring(so_conrep,15,20)).

         /* ORDER # LINE # */
         {pxmsg.i &MSGNUM=8310 &ERRORLEVEL=1 &MSGBUFFER=l_msgdesc[3]
                  &MSGARG1=sod_nbr
                  &MSGAR2=sod_line}

         if so_db <> global_db then do:

            /* NOT IN DATABASE #, ORDER NOT SELECTED         */
            {pxmsg.i &MSGNUM=3819 &ERRORLEVEL=2 &MSGBUFFER=l_msgdesc[1]
                     &MSGARG1=so_db}

            put unformatted
               skip(2)
               l_msgdesc[1]
               skip
               l_msgdesc[3]
               skip(1).

            next.

         end.

         /* CHECK THAT INVENTORY DATABASE IS CONNECTED */
         find si_mstr where si_site = scx_shipfrom no-lock.

         if global_db > "" and not connected (si_db) then do:

            /* ORDER NOT SELECTED, DATABASE # NOT CONNECTED */
            {pxmsg.i &MSGNUM=3820 &ERRORLEVEL=2 &MSGBUFFER=l_msgdesc[2]
                     &MSGARG1=si_db}

            put unformatted
               skip(2)
               l_msgdesc[2]
               skip
               l_msgdesc[3]
               skip(1).

            next.

         end.

         do ctr = 1 to 3:

            if not process_schd[ctr] then
               next.
            schtype = ctr.

            for each sch_mstr
               where sch_type = schtype
                 and sch_nbr = sod_nbr and sch_line = sod_line
                 and (sch_cr_date >= date_from or date_from = ?)
                 and (sch_cr_date <= date_to or date_to = ?)
                 and (not inactive_only or
                      inactive_only and sch_rlse_id <>
                                  sod_curr_rlse_id[schtype])
            exclusive-lock:

               {gprun.i ""rciq1a.p""
                  "(input sch_type,
                    input sch_nbr,
                    input sch_line,
                    input sch_rlse_id,
                    input no)"}

               if rdelete then do:

                  header-needed = yes.

                  for each schd_det
                     where schd_type = sch_type
                       and schd_nbr  = sch_nbr
                       and schd_line = sch_line
                       and schd_rlse_id = sch_rlse_id
                  exclusive-lock:

                     {gprun.i ""rcscmtc.p""
                        "(input recid(schd_det), output schd-error)"}

                     if schd-error then do:
                        header-needed = no.
                        leave.
                     end. /* IF SCHD-ERROR THEN */

                     if archive then do:
                        export stream history "schd_det".
                        export stream history schd_det.
                     end.

                  end.

                  if header-needed = no then next.

                  if archive and not detail_only then do:
                     export stream history "sch_mstr".
                     export stream history sch_mstr.
                  end.

                  /* Special processing for active schedules */
                  if sod_curr_rlse_id[schtype] = sch_rlse_id then do:
                     {gprun.i ""rcdela.p""
                        "(input recid(sod_det),
                          input schtype,
                          input recid(sch_mstr),
                          input detail_only)"}
                  end. /* if sod_curr_rlse_id[schtype] = ... */
                  else do:
                     {gprun.i ""rcschdel.p""
                        "(input recid(sch_mstr),
                          input detail_only)"}
                  end.

               end. /* if rdelete  */

            end. /* for each sch_mstr */

         end. /* do ctr */

         if using_seq_schedules and incl_seq then do:
            {gprunmo.i
               &program = ""rcsqdel.p""
               &module = "ASQ"
               &param = """(input recid(scx_ref),
                            input recid(sod_det),
                            input detail_only,
                            input inactive_only,
                            input rdelete,
                            input archive)"""}
         end.

         
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      end. /* for each scx_ref */

   end. /* if sortoption = 1 */

   else
   if sortoption = 2 then do:

      for each scx_ref no-lock
         where scx_type = 1
           and scx_shipfrom >= shipfrom_from and scx_shipfrom <= shipfrom_to
           and scx_shipto >= shipto_from and scx_shipto <= shipto_to
           and scx_part >= part_from and scx_part <= part_to
           and scx_po >= po_from and scx_po <= po_to
           and scx_custref >= custref_from and scx_custref <= custref_to
           and scx_modelyr >= modelyr_from and scx_modelyr <= modelyr_to
           and scx_order  >= order_from  and scx_order <= order_to,
           each sod_det no-lock
          where sod_nbr = scx_order and sod_line = scx_line
           and sod_dock >= dock_from and sod_dock <= dock_to,
           each so_mstr no-lock
           where so_nbr = sod_nbr
             and so_cust >= cust_from and so_cust <= cust_to
      break by sod_part by scx_shipfrom by so_cust by scx_shipto
            by scx_order by sod_dock by sod_contr_id
            by scx_custref by scx_modelyr:

         /* Only select orders created in the current database */
         assign
            so_db = trim(substring(so_conrep,15,20)).

         /* ORDER # LINE # */
         {pxmsg.i &MSGNUM=8310 &ERRORLEVEL=1 &MSGBUFFER=l_msgdesc[3]
                  &MSGARG1=sod_nbr
                  &MSGAR2=sod_line}

         if so_db <> global_db then do:

            /* NOT IN DATABASE #, ORDER NOT SELECTED         */
            {pxmsg.i &MSGNUM=3819 &ERRORLEVEL=2 &MSGBUFFER=l_msgdesc[1]
                     &MSGARG1=so_db}

            put unformatted
               skip(2)
               l_msgdesc[1]
               skip
               l_msgdesc[3]
               skip(1).

            next.

         end.

         /* CHECK THAT INVENTORY DATABASE IS CONNECTED */
         find si_mstr where si_site = scx_shipfrom no-lock.

         if global_db > "" and not connected (si_db) then do:

            /* ORDER NOT SELECTED, DATABASE # NOT CONNECTED */
            {pxmsg.i &MSGNUM=3820 &ERRORLEVEL=2 &MSGBUFFER=l_msgdesc[2]
                     &MSGARG1=si_db}

            put unformatted
               skip(2)
               l_msgdesc[2]
               skip
               l_msgdesc[3]
               skip(1).

            next.

         end.

         do ctr = 1 to 3:

            if not process_schd[ctr] then
               next.
            schtype = ctr.

            for each sch_mstr
               where sch_type = schtype
                 and sch_nbr = sod_nbr and sch_line = sod_line
                 and (sch_cr_date >= date_from or date_from = ?)
                 and (sch_cr_date <= date_to or date_to = ?)
                 and (not inactive_only or
                      inactive_only and sch_rlse_id <>
                          sod_curr_rlse_id[schtype])
            exclusive-lock:

               {gprun.i ""rciq1a.p""
                  "(input sch_type,
                    input sch_nbr,
                    input sch_line,
                    input sch_rlse_id,
                    input no)"}

               if rdelete then do:

                  header-needed = yes.

                  for each schd_det
                     where schd_type = sch_type
                       and schd_nbr = sch_nbr
                       and schd_line = sch_line
                       and schd_rlse_id = sch_rlse_id
                  exclusive-lock:

                     {gprun.i ""rcscmtc.p""
                        "(input recid(schd_det),
                          output schd-error)"}

                     if schd-error then do:
                        header-needed = no.
                        leave.
                     end. /* IF SCHD-ERROR THEN */

                     if archive then do:
                        export stream history "schd_det".
                        export stream history schd_det.
                     end.

                  end. /* for each schd_det */

                  if header-needed = no then
                     next.

                  if archive and not detail_only then do:
                     export stream history "sch_mstr".
                     export stream history sch_mstr.
                  end.

                  /* Special processing for active schedules */
                  if sod_curr_rlse_id[schtype] = sch_rlse_id then do:
                     {gprun.i ""rcdela.p""
                        "(input recid(sod_det),
                          input schtype,
                          input recid(sch_mstr),
                          input detail_only)"}
                  end. /* if sod_curr_rlse_id[schtype] = ... */
                  else do:
                     {gprun.i ""rcschdel.p""
                        "(input recid(sch_mstr),
                          input detail_only)"}
                  end.

               end. /* if rdelete */

            end. /* for each sch_mstr */

         end. /* do ctr */

         if using_seq_schedules and incl_seq then do:
            /* Sequence Schedule Archive/Delete */
            {gprunmo.i
               &program = ""rcsqdel.p""
               &module = "ASQ"
               &param = """(input recid(scx_ref),
                            input recid(sod_det),
                            input detail_only,
                            input inactive_only,
                            input rdelete,
                            input archive)"""}
         end.

         
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      end. /* for each scx_ref */

   end. /* if sortoption = 2 */

   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


   output stream history close.

end.

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" shipfrom_from shipfrom_to cust_from cust_to shipto_from shipto_to dock_from dock_to part_from part_to po_from po_to custref_from custref_to modelyr_from modelyr_to order_from order_to date_from date_to sortoption incl_plan incl_ship incl_reqd incl_seq inactive_only detail_only rdelete archive "} /*Drive the Report*/
